//
//  MapStarView.cpp
//  FruitCrush
//
//  Created by gaoyu on 15/8/27.
//
//

#include "MapStarView.h"
USING_NS_CC;

#define WIDTH    75
#define HEIGHT   25

#define STARX_PAD    (12)
#define STARY_PAD    (6)


MapStarView::MapStarView()
{
}

MapStarView* MapStarView::create(int num)
{
    MapStarView *pRet = new(std::nothrow) MapStarView();
    if (pRet && pRet->init(num)){
        pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}

bool MapStarView::init(int num)
{
    if (!Layer::init()) {
        return false;
    }
    starInit(num);
    
    
    return true;
}

void MapStarView::starInit(int num)
{
    auto cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("CommonIcon.plist");
    
    if(num >= 1){
        Sprite *star1 = Sprite::createWithSpriteFrameName("MapStar1.png");
        star1->setAnchorPoint(Vec2::ZERO);
        star1->setPosition(Point(0,STARY_PAD));
        this->addChild(star1);
    }
    
    if(num >= 2){
        Sprite *star2 = Sprite::createWithSpriteFrameName("MapStar2.png");
        star2->setAnchorPoint(Vec2::ZERO);
        star2->setPosition(Point(STARX_PAD,0));
        this->addChild(star2);
    }
    
    if(num >= 3){
        Sprite *star3 = Sprite::createWithSpriteFrameName("MapStar3.png");
        star3->setAnchorPoint(Vec2::ZERO);
        star3->setPosition(Point(STARX_PAD*2,STARY_PAD));
        this->addChild(star3);
    }
    
}

void MapStarView::setStarNum(int num){
	this->removeAllChildren();
	starInit(num);
}

Size MapStarView::getMySize()
{
    return Size(WIDTH,HEIGHT);
}